#include "Tilemap.h"

Tilemap::Tilemap(int width, int height)
 : m_width(width), m_height(height)
{
	allocate();
}

Tilemap::~Tilemap() {
	free();
}

void  Tilemap::fill(Tile tile) {
	for (int i = 0; i < m_height; i++)
		for (int j = 0; j < m_width; j++)
			m_tiles[i][j] = tile;
}

void Tilemap::set(int x, int y, Tile tile) {
	m_tiles[y][x] = tile;
}

void Tilemap::allocate() {
	m_tiles = new Tile*[m_height];
	for (int i = 0; i < m_height; i++) {
		m_tiles[i] = new Tile[m_width];
	}
}

void Tilemap::free() {
	for (int i = 0; i < m_height; i++) {
		delete[] m_tiles[i];
	}
	delete[] m_tiles;
}